package com.lac.component.rabbitmq.seq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author xiaokuixiao
 * date2025/7/1 15:11
 */
@Configuration
public class TripleQueueConfig {
    @Bean
    public DirectExchange directExchange(){
        DirectExchange directExchange = new DirectExchange("triple_exchange");
        return directExchange;
    }

    @Bean
    public Queue tripleQueueOne(){
        Queue queue = creatQueue("triple_queue_one");
        return queue;
    }

    @Bean
    public Queue tripleQueueTwo(){
        Queue queue = creatQueue("triple_queue_two");
        return queue;
    }
    @Bean
    public Queue tripleQueueThree(){
        Queue queue = creatQueue("triple_queue_three");
        return queue;
    }

    @Bean
    public Binding bindingOne(){
        return BindingBuilder.bind(tripleQueueOne()).to(directExchange()).with("triple-one");
    }

    @Bean
    public Binding bindingTwo(){
        return BindingBuilder.bind(tripleQueueTwo()).to(directExchange()).with("triple-two");
    }
    @Bean
    public Binding bindingThree(){
        return BindingBuilder.bind(tripleQueueThree()).to(directExchange()).with("triple-three");
    }

    private Queue creatQueue(String name) {
        // 创建一个 单活模式 队列
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-single-active-consumer", true);
        return new Queue(name, true, false, false, args);
    }


}